﻿@page "/CaviarBase/CodeFileGenerate"

<div>
    <Steps Current="current">
        @foreach (var item in steps)
        {
            <Step Title="@item.Title" Subtitle="@item.Content" />
        }
    </Steps>
    <div class="steps-action">
        <Space>
            <SpaceItem>
                @if (current > 0 && current < steps.Length - 1)
                {
                    <Button Type="primary" OnClick="OnPreClick">上一步</Button>
                }
            </SpaceItem>
            <SpaceItem>
                @if (current < steps.Length - 2 && current > 0)
                {
                    <Button Type="primary" OnClick="OnNextClick">下一步</Button>
                }
            </SpaceItem>
            <SpaceItem>
                @if (current == steps.Length - 2)
                {
                    <Button Type="primary" Danger OnClick=@(() => { OnGenerateClick(); })>
                        生成
                    </Button>
                }

            </SpaceItem>
        </Space>



    </div>
    <div class="steps-content">
        @switch (current)
        {
            case 0:
                <Table TItem="ViewModelFields" DataSource="@Models">
                    <Column @bind-Field="@context.TypeName">
                    </Column>
                    <Column @bind-Field="@context.DisplayName">
                    </Column>
                    <ActionColumn Title="操作">
                        <Space Size=@("middle")>
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" OnClick='()=>
                                                                            {
                                                                                GenerateData.EntityName = context.TypeName;
                                                                                GenerateData.EntityNamespace = context.FullName;
                                                                                GenerateData.OutName = context.TypeName;
                                                                                GenerateData.EntityDisplayName = context.DisplayName;
                                                                                GenerateData.ModelName = context.DisplayName;
                                                                                OnNextClick();
                                                                            }'>选择</Button>
                            </SpaceItem>
                        </Space>
                    </ActionColumn>
                </Table>
                break;
            case 1:
                <div style="margin-bottom:16px;margin-top:16px;">
                    <Form Model="GenerateData" @ref="GenerateFrom">
                        <Space Direction="DirectionVHType.Vertical" Size="@("large")">
                            <FormItem>
                                <AntDesign.Input Placeholder="请输入生成的文件名" @bind-Value="@context.OutName">
                                    <AddOnBefore>目录名:</AddOnBefore>
                                </AntDesign.Input>
                            </FormItem>
                            <FormItem>
                                <AntDesign.Input Placeholder="请输入模块名称" @bind-Value="@context.ModelName">
                                    <AddOnBefore>模块名称:</AddOnBefore>
                                </AntDesign.Input>
                            </FormItem>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                            <SpaceItem>
                                <span style="margin-right:8px">前端:</span>
                                <CheckboxGroup Value="GenerateData.Page" Options="@_pageOptions" OnChange="OnPageChange" />
                            </SpaceItem>
                            <SpaceItem>
                                <span style="margin-right:8px">后端:</span>
                                <CheckboxGroup Value="GenerateData.WebApi" Options="@_webApi" OnChange="OnWebApiChange" />
                            </SpaceItem>
                            <SpaceItem>
                                <span style="margin-right:8px">其他:</span>
                                <CheckboxGroup Value="GenerateData.Config" Options="@_configOptions" OnChange="OnConfigChange" />
                            </SpaceItem>
                        </Space>
                        
                    </Form>
                </div>
                break;
            case 2:
                <Tabs DefaultActiveKey="1" @bind-ActiveKey="@nKey">
                    @foreach (var item in lstTabs)
                    {
                        <TabPane Key="@item.KeyName" Tab="@item.TabName">
                            <ChildContent>
                                <CavHighlightedCode Code="@item.Content" CanLoad="true" Language="csharp"></CavHighlightedCode>
                            </ChildContent>
                        </TabPane>
                    }
                </Tabs>
                break;
            case 3:
                <Result Status="@ResultStatus"
                        Title="@ReusltTitle"
                        SubTitle="@ResultSubTitle">
                    <Extra>
                        <Button Type="primary" OnClick='()=> { navigation.NavigateTo("/"); }'>返回首页</Button>
                        <Button OnClick='()=> { current = 0; }'>继续生成</Button>
                    </Extra>

                </Result>
                break;
            default:
                break;
        }
    </div>

</div>

<style>
    .steps-content {
        margin-top: 16px;
        border: 3px dashed #e9e9e9;
        border-radius: 6px;
        @UserConfig.Background;
        text-align: center;
    }

    .steps-action {
        margin-top: 24px;
    }
</style>

@inject NavigationManager navigation
@inject UserConfig UserConfig
@code {
    string Code = "";
    public class StepItem
    {
        public string Title { get; set; }
        public string Content { get; set; }
    }

    public int current { get; set; } = 0;

    public StepItem[] steps =
    {
        new StepItem {Title = "选择生成模块", Content = ""},
        new StepItem {Title = "功能配置", Content = ""},
        new StepItem {Title = "查看代码", Content = ""},
        new StepItem {Title = "生成结果", Content = ""}
    };

}